package com.sgcc.fj.pmos.e_fj_order.adapter;


import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.arouter.order.OrderArouterPath;
import com.sgcc.fj.pmos.arouter.common.CommonArouterPath;
import com.sgcc.fj.pmos.common.http.DownloadUtil;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.fj.pmos.common.utils.TimePickerUtil;
import com.sgcc.fj.pmos.e_fj_order.bean.SupplementContractBean;

import java.io.File;

/**
 * 补充协议 adapter
 *
 * @author ChaoAJ
 * @time 2022/11/8 10:15
 */
public class SupplementContractAdapter extends BaseQuickAdapter<SupplementContractBean.DataDTO,
        BaseViewHolder> {


    public SupplementContractAdapter() {
        super(R.layout.item_supplement_contract);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, SupplementContractBean.DataDTO bean) {
        baseViewHolder.setText(R.id.tvEntName, bean.getMembersSdName());
        baseViewHolder.setText(R.id.tvUserName, bean.getMembersUsersName());
        baseViewHolder.setText(R.id.tvOriginator, bean.getLaunchType() == 0 ? "零售用户" : bean.getLaunchType() == 1
                ? "售电公司" : "");
        baseViewHolder.setText(R.id.tvTime, DateUtils.getStrng_to_Times_ymd_5(bean.getCreateDate()));

        baseViewHolder.getView(R.id.tvSeePrice).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {//查看补充差价
                ARouter.getInstance()
                        .build(OrderArouterPath.ORDER_SUPPLEMENTDIFFERENCE)
                        .withString("monthlyDifprice", bean.getMonthlyDifprice())
                        .navigation();
            }
        });
        baseViewHolder.getView(R.id.tvSeeAgree).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {//查看补充协议
                DownloadUtil.get().downloadPdf(getContext(), bean.getFileId(), new DownloadUtil.OnDownloadListener() {
                    @Override
                    public void onDownloadSuccess(File file) {
                        ARouter.getInstance()
                                .build(CommonArouterPath.COMMON_PDFPREVIEW)
                                .withString("mFilePath", file.getAbsolutePath())
                                .navigation();
                    }

                    @Override
                    public void onDownloading(int progress) {

                    }

                    @Override
                    public void onDownloadFailed(Exception e) {

                    }
                });
            }
        });

    }
}
